<?php
if (!defined('ZZQSS')){
	die("Access Denied");
}
/**
 * MchangesClass订单操作类
 * add()
 * del()
 * state()
 * getdata()
 *
 */
class MchangesClass {
	var $db;
	var $table;
	var $tablepre;
	function __construct(){
		//设置全局变量
		global $db,$tablepre;
		$this->db=$db;
		$this->tablepre=$tablepre;
		$this->table=$tablepre."moneychanges";
	}
	function MchangesClass() {
		$this->__construct();
	}
	/**
	 * 添加货币变动记录
	 *
	 * @param string $order_sn
	 * @param int $order_price
	 * @param int $paymoney
	 * @param string $payname
	 * @param int $pay_fee
	 * @param int $tid (1收款2退款)
	 * @return OK/缺少参数
	 */
	function add($order_sn,$order_price,$paymoney,$payname="",$pay_fee=0,$tid=1){
		$timestamp=time();
		if(!empty($order_sn) && !empty($order_price) && !empty($paymoney)){
			$this->db->query("insert into {$this->table}(order_sn,order_price,payname,paymoney,pay_fee,addtime,tid) VALUES('{$order_sn}','{$order_price}','{$payname}','{$paymoney}','{$pay_fee}',$timestamp,'{$tid}')");						
			return "OK";
		}return "缺少参数";
	}
	/**
	 * 清空记录
	 *
	 * @return true/false
	 */
	function clear(){
		$this->db->query("delete from {$this->table} where 1");	
		return true;	
	}

	/**
	 * 获取数据数组
	 *
	 * @param string $limit
	 * @param string $where
	 * @param string $orderby
	 * @return array
	 */
	function getdata($limit="",$where="",$orderby="",$type="")
	{
		$tempdata=array();
		if(!empty($limit))$limit=" limit $limit ";
		if(!empty($where))$where=" where $where ";
		if(!empty($orderby))$orderby=" order by $orderby ";else $orderby=" order by mid desc";
		if($type=="ALL")$addsql=" AS O left join {$this->tablepre}order AS G ON O.order_sn=G.order_sn ";

		$sql="select * from {$this->table}{$addsql}{$where}{$orderby}{$limit}";
		$query =$this->db->query($sql);
		while($value = $this->db->fetch_array($query)) {
			//此处可进行数据整理
			$tempdata[]=$value;
		}
		return $tempdata;
	}
	function getcount($where=""){
		if(!empty($where))$where=" where $where";
		$count= $this->db->result_first("Select count(*) From `$this->table` $where");
		return $count;
	
	}
}
?>